package cn.by.wms.service;

import cn.smart.core.util.UserSessionContext;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.by.wms.entity.*;
import cn.by.wms.dao.VendorDao;
import cn.by.wms.service.VendorService;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ;(206_vendor)表服务实现类
 * @author : heimi
 * @date : 2024-11-24
 */
@Service
public class VendorService {
     
    @Autowired
    private VendorDao vendorDao;
    
    public List<Vendor> select(VendorQuery query) {
        LambdaQueryWrapper<Vendor> wapper =new LambdaQueryWrapper();
        wapper.eq(query.getId() != null, Vendor::getId, query.getId() );
        wapper.like(query.getName() != null, Vendor::getName, query.getName() );
        wapper.like(query.getEmail() != null, Vendor::getEmail, query.getEmail());
        wapper.like(query.getTel() != null, Vendor::getTel, query.getTel());
        wapper.eq(query.getStatus() != null, Vendor::getStatus, query.getStatus());
        wapper.like(query.getProvince() != null, Vendor::getProvince, query.getProvince());
        wapper.like(query.getCity() != null, Vendor::getCity, query.getCity());
        wapper.like(query.getCounty() != null, Vendor::getCounty, query.getCounty());
        wapper.like(query.getAddress() != null, Vendor::getAddress, query.getAddress());
        return vendorDao.selectList(wapper);
    }
    
    public Integer insert(Vendor vendor) {
        return vendorDao.insert(vendor);
    }
    
    public Integer update(Vendor vendor) {
        LambdaUpdateWrapper<Vendor> wapper =new LambdaUpdateWrapper();
        wapper.eq(Vendor::getId, vendor.getId());
        wapper.set(vendor.getName() != null, Vendor::getName, vendor.getName());
        wapper.set(vendor.getEmail() != null, Vendor::getEmail, vendor.getEmail());
        wapper.set(vendor.getImg() != null, Vendor::getImg, vendor.getImg());
        wapper.set(vendor.getTel() != null, Vendor::getTel, vendor.getTel());
        wapper.set(vendor.getStatus() != null, Vendor::getStatus, vendor.getStatus());
        wapper.set(vendor.getBrief() != null, Vendor::getBrief, vendor.getBrief());
        wapper.set(vendor.getProvince() != null, Vendor::getProvince, vendor.getProvince());
        wapper.set(vendor.getCity() != null, Vendor::getCity, vendor.getCity());
        wapper.set(vendor.getCounty() != null, Vendor::getCounty, vendor.getCounty());
        wapper.set(vendor.getAddress() != null, Vendor::getAddress, vendor.getAddress());
        wapper.set(vendor.getSeq() != null, Vendor::getSeq, vendor.getSeq());
        return vendorDao.update(wapper);
    }
    
    public Integer delete(Integer id) {
        return vendorDao.deleteById(id);
    }
    
 
}